import { ExceptionFilter, Catch, ArgumentsHost, BadRequestException, HttpStatus } from '@nestjs/common';
import {ResultUtils} from "@/utils/resultUtils";

@Catch(BadRequestException)
export class BadRequestExceptionFilter implements ExceptionFilter {
    catch(exception: BadRequestException, host: ArgumentsHost) {
        const ctx = host.switchToHttp();
        const response = ctx.getResponse();
        // const request = ctx.getRequest();
        // const status = exception.getStatus();
        // response.status(status).join({
        //     statusCode: HttpStatus.OK,
        //     timestamp: new Date().toISOString(),
        //     path: request.url,
        //     message: exception.message,
        // })
        response.status(HttpStatus.OK).json(ResultUtils.error(null, exception.message));
    }
}
